/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-10 14:51:18
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-10 17:43:28
 * @FilePath: \vue3_admin_template\project\src\api\acl\menu\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//菜单接口地址
import request from '@/utils/request'
import { PermissionResponseData, MenuParams } from './type'
enum API {
  //获取全部菜单与按钮的标识数据
  ALLPERMISSION_URL = '/admin/acl/permission',
  //删除菜单
  REMOVEALL_URL = '/admin/acl/permission/remove/', //{id}
  //给某一级菜单添加子菜单
  ADDMENU_URL = '/admin/acl/permission/save/',
  //更新某一级菜单已有子菜单
  UPDATEMENU_URL = '/admin/acl/permission/update',
}

//获取表单数据
export const reqAllPermission = () =>
  request.get<any, PermissionResponseData>(API.ALLPERMISSION_URL)

//删除菜单
export const reqRemoveAllPermission = (permissionId: number) =>
  request.delete<any, any>(API.REMOVEALL_URL + `${permissionId}`)

export const addOrUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEMENU_URL, data)
  } else {
    return request.post<any, any>(API.ADDMENU_URL, data)
  }
}
